﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace DAH_TD_
{
    public class HUD
    {
        private SpriteBatch spriteBatch;
        private Game1 game;
        private Rectangle mouseCul;
        Texture2D back;
        Texture2D turret;
        Texture2D support;
        Texture2D dot;
        Texture2D splash;
        Texture2D life;
        Texture2D power;
        public Texture2D mouseSprite;
        public HUDelement[] hudElements;
        public Color mouseColor = Color.Blue;
        TileMap map;
        int j = 0;
        Boolean isActive = false;
        public String infoText= "";
        public Boolean infoTextActive = false;
        Vector2 infoTextPos= new Vector2(320, 430);
        Color infoTextColor = Color.GreenYellow;

        public HUD (Game1 game, ContentManager content)
        {
            this.game = game;
            this.mouseCul = game.mouseCul;
            mouseSprite = content.Load<Texture2D>("Graphics/MouseSprite1");
            back = content.Load<Texture2D>("Graphics/blackpx");
            turret = content.Load<Texture2D>("Graphics/Licht/Turm");
            support = content.Load<Texture2D>("Graphics/Licht/Support");
            dot = content.Load<Texture2D>("Graphics/Licht/DOT-Gift");
            splash = content.Load<Texture2D>("Graphics/Licht/Splash");
            life = content.Load<Texture2D>("Graphics/Life");
            power = content.Load<Texture2D>("Graphics/Power");

            hudElements = new HUDelement[5];
            hudElements[0] = new HUDelement(turret, new Rectangle(20, 405, 50, 50), true);
            hudElements[1] = new HUDelement(support, new Rectangle(90, 405, 50, 50), true);
            hudElements[2] = new HUDelement(dot, new Rectangle(160, 405, 50, 50), true);
            hudElements[3] = new HUDelement(splash, new Rectangle(230, 405, 50, 50), true);
            hudElements[4] = new HUDelement(mouseSprite, new Rectangle(mouseCul.X, mouseCul.Y, 30, 30), false);
            hudElements[4].color = mouseColor;
            this.map = game.getMap();
        }

        public void Update()
        {       
        }

        protected void UnloadContent()
        {
        }

    
        public void Draw(SpriteBatch spriteBatch, List<Tower> towers)
        {
            spriteBatch.Draw(back, new Rectangle(0, 400, 800, 80), Color.White);
            spriteBatch.Draw(hudElements[0].texture, hudElements[0].rectangle, hudElements[0].color);
            spriteBatch.Draw(hudElements[1].texture, hudElements[1].rectangle, hudElements[1].color);
            spriteBatch.Draw(hudElements[2].texture, hudElements[2].rectangle, hudElements[2].color);
            spriteBatch.Draw(hudElements[3].texture, hudElements[3].rectangle, hudElements[3].color);
            spriteBatch.Draw(hudElements[4].texture, hudElements[4].rectangle, hudElements[4].color);

            for (int i = 0; i < towers.Count(); i++)
            {
                spriteBatch.Draw(towers[i].texture, towers[i].boundarie, Color.Green);
                j = i;
            }

            if (towers.Count() > 0)
            {
                spriteBatch.DrawString(game.font1, towers[j].getPos().X + "  " + towers[j].getPos().Y, new Vector2(10, 10), Color.YellowGreen);
            }

            if (infoTextActive)
            {
                spriteBatch.DrawString(game.font2, infoText, infoTextPos, infoTextColor);
            }
            spriteBatch.Draw(life, new Rectangle(680, 405, 50, 50), Color.White);
            spriteBatch.Draw(power, new Rectangle(550, 405, 50, 50), Color.White);
        }
    }
}
